package com.transportation.app.view

import android.content.Context
import android.text.Editable
import android.text.TextWatcher
import android.widget.EditText
import com.lxj.xpopup.core.CenterPopupView
import com.transportation.app.BusViewModel
import com.transportation.app.utils.ToastUtils

/**
 * 现金付款弹窗
 */
class CashPayPopup(context: Context) : CenterPopupView(context) {

    private var upPeopleNum = 0

    private var downPeopleNum = 0

    private var edit_view: EditText? = null

    private var viewModel: BusViewModel? = null

    // 返回自定义弹窗的布局
    override fun getImplLayoutId(): Int = 0

    override fun onCreate() {
        super.onCreate()
        edit_view?.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {

            }
            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {

            }
            override fun afterTextChanged(s: Editable?) {
                s?.let {
                    try {
//                        val ss = it.toString()
//                        actualAmount = ss.toDouble()
//                        if (actualAmount >= amount) {
//                            tv_small_cash_view?.text = "找零： ${actualAmount - amount}"
//                        } else {
//                            tv_small_cash_view?.text = "找零： "
//                        }
                    } catch (e: Exception) {
                    }
                }
            }
        })

        viewModel?.setUpDownPeopleLiveData?.observe(this) {
            if (it != null) {
                ToastUtils.show("更新成功~")
                upPeopleNum = 0
                downPeopleNum = 0
                dismiss()
            }
        }
    }

    override fun onDestroy() {
        super.onDestroy()
    }

}